package com.dingwen.treasure.business.controller;

import cn.hutool.json.JSONUtil;
import com.dingwen.treasure.base.controller.BaseViewController;
import com.dingwen.treasure.base.pojo.vo.Result;
import com.dingwen.treasure.business.model.dto.EasyCacheDto;
import com.dingwen.treasure.core.annotation.EasyCache;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * EasyCache 控制器
 *
 * @author dingwen
 * @date 2022/05/03
 */
@Api(tags = "EasyCache，自定义注解实现优雅缓存业务")
@RestController
@RequestMapping("easy/cache")
public class EasyCacheController implements BaseViewController {

    /**
     * 轻松缓存
     *
     * @param id           业务参数
     * @param easyCacheDto 轻松缓存dto
     * @return {@link Result}<{@link String}>
     */
    @PostMapping("")
    @ApiOperation("测试方法")
    @EasyCache(keyParams = {
            "#id",
            "#easyCacheDTO.getId()",
            "#easyCacheDTO.getName()"},
            time = 100,
            returnType = Result.class)
    public Result<String> easyCache(@RequestParam Long id, @RequestBody EasyCacheDto easyCacheDto) {
        return success(JSONUtil.toJsonStr(easyCacheDto));
    }
}
